import { baseUrl } from "@/utils/config";
async function request (url, method, data, params) {
    const token = await uni.getStorageSync('token') || ''
    const header = {
        Authorization: token
    }
    return new Promise((resolve, reject) => {
        uni.request({
            url: `${baseUrl}${url}${params ? params : ''}`,
            timeout: 60000,
            data,
            method,
            header: token ? header : {},
            success: (res) => {
                if(res.data.code === 200) {
                    resolve(res.data)
                } else {
                    console.log('resssssssss', res)
                    uni.showModal({
                        content: res.data.msg || res.data.message || '程序错误！请联系管理员！'
                    })
                    reject(res.data)
                }
            },
            fail: (err) => {
                console.log('err', err)
                uni.showModal({
                    content: err.data.data.msg || '网络错误！请稍后再试！'
                })
                reject(err.data)
            }
        });
    })
}
export default request
